<template>
  <div class="container gray">
    <!-- 头部 -->
    <div class="header">
      <span class="iconfont back_icon" @click="back">&#xe616;</span>
      <h3>我的收货地址</h3>
    </div>
    <div class="main" v-if="this.address">
      <h3 class="address_name">{{ this.address.cgn_address}}</h3>
      <p>
        <span class="address_info">{{ this.address.cgn_name }}</span>
        <span class="address_info">{{ this.address.cgn_tel }}</span>
      </p>
      <div class="edit_icon iconfont" @click="modifyAddress">&#xe626;</div>
    </div>
    <div class="add_btn" @click="toAddAddress" v-else>新增收货地址</div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'ManageAddress',
  computed: {
    ...mapState(['address'])
  },
  methods: {
    // 返回上一页
    back () {
      this.$router.push('/profile')
    },
    // 跳转到新增地址页面
    toAddAddress () {
      this.$router.push('/addaddress')
    },
    modifyAddress () {
      this.$router.push('/modifyaddress')
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  overflow: hidden;
  width: 15rem;
  height: 100%;
  overflow-y: scroll;
    &::-webkit-scrollbar {
      display: none;
    }
}
// 头部
.header {
  position: relative;
  width: 100%;
  height: 1.6rem;
  line-height: 1.6rem;
  font-size: .72rem;
  text-align: center;
  background: #fff;
  .back_icon {
    position: absolute;
    left: .4rem;
    font-size: .8rem;
    top: 50%;
    transform: translateY(-50%);
  }
}
// 已有地址列表
.main {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 100%;
  height: 4rem;
  background: #fff;
  padding: .4rem;
  margin-top: .4rem;
  .address_name {
    overflow: hidden;
    font-size: .64rem;
    font-weight: 500;
    color: #000;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .address_info {
    font-size: .64rem;
    color: #999;
  }
  .edit_icon {
    position: absolute;
    right: .4rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: .8rem;
    color: #000;
  }
}
// 新增收货地址按钮
.add_btn {
  width: 5rem;
  height: 2rem;
  line-height: 2rem;
  font-size: .72rem;
  color: #fff;
  text-align: center;
  background: rgb(255, 20, 147);
  border-radius: .2rem;
  margin: 2rem auto;
}
</style>
